package com.totoro.springboot.druid.repository;

import com.totoro.springboot.druid.model.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

/**
 * Created by Niki on 2018/2/6 20:00
 */

public interface UserRepository extends JpaRepository<User, Long> {

    User findByName(String name);

    User findByNameAndAge(String name, Integer age);

    @Query("from User u where u.name = ?1")
    User findUser(String name);

    @Modifying
    @Query("update User u set u.name=?2, u.age=?3 where u.id=?1")
    int updateUser(Long id, String name, Integer age);
}
